package com.jzy.stock.stockRoom.controller;

import com.jzy.stock.stockRoom.model.*;
import com.jzy.stock.stockRoom.service.StockService;
import com.jzy.stock.util.ResultBuildVo;
import com.jzy.stock.util.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author 贾志宇
 * @create 2022-07-11-16:55
 */
@RestController
@CrossOrigin
@Api(value = "StockController",description = "库房页面所有功能接口")
public class StockController {

    @Autowired
    private StockService stockService;

    @ApiOperation("库房标识添加接口")
    @PostMapping("warehouseTag/add")
    public ResultVo addTag(@RequestBody @Valid IdentifyAddVo identifyAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.add(identifyAddVo);
    }
    @ApiOperation("库房添加接口")
    @PostMapping("warehouse/add")
    public ResultVo add1(@RequestBody @Valid StockRoomAddVo stockRoomAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.add1(stockRoomAddVo);
    }

    @ApiOperation("库房标识修改接口")
    @PostMapping("warehouseTag/update")
    public ResultVo update(@RequestBody @Valid IdentifyUpdateVo identifyUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.update(identifyUpdateVo);
    }
    @ApiOperation("库房修改接口")
    @PostMapping("warehouse/update")
    public ResultVo update1(@RequestBody @Valid StockRoomUpdateVo stockRoomUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.update1(stockRoomUpdateVo);
    }

    @ApiOperation("库房标识查询接口")
    @PostMapping("warehouseTag/queryPage")
    public ResultVo queryPage(@RequestBody @Valid IdentifySelectVo identifySelectVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.queryPage(identifySelectVo);
    }
    @ApiOperation("库房标识下拉框接口")
    @PostMapping("warehouse/queryWarehouseTagList")
    public ResultVo queryWarehouseTagList(){
        return stockService.queryWarehouseTagList();
    }

    @ApiOperation("库房查询接口")
    @PostMapping("warehouse/queryPage")
    public ResultVo queryPage1(@RequestBody @Valid StockRoomSelectVo stockRoomSelectVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.queryPage1(stockRoomSelectVo);
    }

    @ApiOperation("库房标识状态修改接口")
    @PostMapping("warehouseTag/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid UpdateStatusVo updateStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.updateStatus(updateStatusVo);
    }
    @ApiOperation("库房状态修改接口")
    @PostMapping("warehouse/updateStatus")
    public ResultVo updateStatus1(@RequestBody @Valid UpdateStatusVo updateStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockService.updateStatus1(updateStatusVo);
    }
}
